<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/assets/js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/assets/js/jquery-ui-1.10.3.min.js"></script>
        
        <!--ckeditor-->
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/ckeditor/ckeditor.js"></script>
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/ckeditor/config.js"></script>
        
        <!--elFinder CSS (REQUIRED)--> 
        <link rel="stylesheet" type="text/css" media="screen" href="<?php echo Yii::app()->baseUrl ?>/css/elfinder.min.css">
        <link rel="stylesheet" type="text/css" media="screen" href="<?php echo Yii::app()->baseUrl ?>/css/theme.css">
        
        <!--elFinder JS (REQUIRED)--> 
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/js/elfinder.min.js"></script>
        
        <!--elFinder translation (OPTIONAL)--> 
       <!--<script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/js/i18n/elfinder.ru.js"></script>-->
        
        <!--elFinder initialization (REQUIRED)--> 
        <script type="text/javascript" charset="utf-8">
            $().ready(function() {
            });
        </script>
        <!-- page specific plugin styles -->
        <link rel="stylesheet" href="<?php echo Yii::app()->baseUrl."/assets/css/jquery-ui-1.10.3.full.min.css"?>" />
        <link rel="stylesheet" href="<?php echo Yii::app()->baseUrl."/assets/css/datepicker.css"?>" />
        <link rel="stylesheet" href="<?php echo Yii::app()->baseUrl."/assets/css/ui.jqgrid.css"?>" />
        <!-- fonts -->
        <link href="<?php echo Yii::app()->baseUrl."/assets/css/ace-fonts.css" ?>" rel="stylesheet" />
        <!-- ace styles -->
        <link href="<?php echo Yii::app()->baseUrl."/assets/css/ace.min.css" ?>" rel="stylesheet" />
        <link href="<?php echo Yii::app()->baseUrl."/assets/css/ace-rtl.min.css" ?>" rel="stylesheet" />
        <link href="<?php echo Yii::app()->baseUrl."/assets/css/ace-skins.min.css" ?>" rel="stylesheet" />
        <title></title>
    </head>
    <body>
        <?php
         try{
                $connection=Yii::app()->db;   // assuming you have configured a "db" connection
                $query="SELECT *  FROM os_news WHERE os_news.sale_id =".Yii::app()->session["saleId"];
                $command=$connection->createCommand($query);
                $dataReader=$command->query();
                $rows_news = array();

                while(($row=$dataReader->read())!==false) {
                    $rows_news[]=$row;
                }
//                $string=json_encode($rows_store);
//                echo $string;
            }catch(Exception $e){
                $result=array('data'=>'','status'=>'fail','error'=>$e->getMessage());
                 echo $string=json_encode($result);
             }        
        ?>
        <div id="main-container" class="main-container">
            <div id="breadcrumbs" class="breadcrumbs">
                <script type="text/javascript">
                    try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){};
                </script>
                <ul class="breadcrumb">
                    <li>
                        <i class="icon-home home-icon"></i>
                        <a href="../site/index"><strong>Trang Chủ</strong></a>
                    </li>
                    <li>
                        <a href="../site/news"><strong>Tin Tức</strong></a>
                    </li>                                                                                                                                       
                    <li>
                        <strong> Sửa Tin Tức </strong>
                    </li>
                </ul><!-- .breadcrumb -->
                
                <div id="nav-search" class="nav-search">
                    <form class="form-search">
                        <span class="input-icon">
                            <input type="text" autocomplete="off" id="nav-search-input" class="nav-search-input" placeholder="Search ...">
                            <i class="icon-search nav-search-icon"></i>
                        </span>
                    </form>
                </div><!-- #nav-search -->
            </div>    
            
            <div class="page-content">
                <div class="page-header">
                    <h1><strong> Sửa Tin Tức</strong></h1>
                </div><!-- /.page-header -->
                <div class="row">
                    <div class="col-xs-12">
            <?php $form=$this->beginWidget('CActiveForm', array(
                'htmlOptions' => array(
                    'enctype' => 'multipart/form-data',
                ),              
            ));?>
                        <!--<form class="form-horizontal" method="POST" enctype="multipart/form-data">-->
                        <fieldset>
                            <div class="form-group">
                        <?php // echo $form->error($model,'name');?>
                                <label class="col-sm-2 control-label no-padding-right">
                                    Tiêu Đề
                                </label>
                                <div class="col-sm-10">
                                    <input class="col-xs-10 col-sm-5" type="text" name="NewsForm[newstitle]" id="NewsForm_newstitle" value="<?php echo $rows_news[$_GET['id']-1]["news_title"]?>"></input>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            
                            <div class="form-group">
                        <?php // echo $form->error($model,'mobile');?>
                                <label class="col-sm-2 control-label no-padding-right">
                                    Thời Gian
                                </label>
                                <div class="col-sm-10">
                                    <input class="col-xs-10 col-sm-5" type="datetime" name="NewsForm[time]" id="NewsForm_time" value="<?php 
                            $time = date('m/d/Y', $rows_news[$_GET['id']-1]["news_time"]);
                            echo $time?>" ></input>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right">
                                    Tin Chính
                                </label>
                                <div class="col-sm-10">
                                    <textarea class="col-xs-10 col-sm-5" rows="5" cols="20" name="NewsForm[newscontent]" id="NewsForm_newscontent"><?php echo $rows_news[$_GET['id']-1]["news_content"]?></textarea>
                                    <!--<input class="col-xs-10 col-sm-5" type="text" name="NewsForm[content]" id="NewsForm_content"></input>-->
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right">
                                    Thông Tin Chi Tiết
                                </label>
                                <div class="col-sm-10">
                                    <textarea class="ckeditor" name="NewsForm[description]" id="NewsForm_description"><?php echo $rows_news[$_GET['id']-1]["news_description"]?></textarea>
                                    <!--<input class="col-xs-10 col-sm-5" type="text" name="NewsForm[description]" id="NewsForm_description"></input>-->
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            
                            <div class="form-group"> 
                                <label class="col-sm-2 control-label no-padding-right">
                                    Ảnh
                                </label>
                                <div class="col-sm-10" >
                            <?php  if($rows_news[$_GET['id']-1]["news_image"] != NULL){ ?>
                            <?php 
//                            echo CHtml::image($_FILES['image'] ['tmp_name']);
//                            echo CHtml::image(Yii::app()->request->baseUrl.'/files/'.$rows_news[$_GET['id']-1]["news_image"],"Image Invalid",array("width"=>200)); 
//                            }
                            ?>
                            <?php // echo CHtml::activeFileField($model, 'image'); ?>
                                    <img src="../../files/<?php echo $rows_news[$_GET['id']-1]['news_image'];?>" onclick="imageClick();" id="LinkImage" name="LinkImage" style="max-height: 600px; max-width: 800px;"/>
                             <?php } else {?>
                                    <img src="../../images/photo.png" onclick="imageClick();" id="LinkImage" name="LinkImage" style="max-height: 600px; max-width: 800px;"/>
                             <?php }?>
                                    <input type="hidden" id="NewsForm_image" name="NewsForm[image]" type="text"/>                            
                                    <p class="help-block">                                
                                        Image must be more than 100x100px and smaller than 3MB
                                    </p>
                                </div>
                            </div>
                            
                            <div class="clearfix"></div>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-2 col-md-10">
                                    <button class="btn btn-sm btn-primary" type="submit" name="submit" value="submit">
                                        <i class="icon-save align-top bigger-125"></i>
                                        Save
                                    </button>
                                    <a class="btn btn-sm" type="button" href="../site/news">                                
                                        Back
                                        <i class="icon-backward align-top bigger-125"></i>
                                    </a>
                                </div>
                            </div>
                        </fieldset>
                        <!--</form>-->
            <?php $this->endWidget(); ?>
                    </div>
                </div>
                
            </div>
        </div>
        <script>
            $(function() {
                $( "#NewsForm_time" ).datepicker();
            });
        </script>
        <script type="text/javascript" charset="utf-8">
            function imageClick(){
                $( "#dialog-message" ).dialog({
                    title:"",
                    height:600,
                    width:1100,
                    modal: true
                });					
                var elf = $('#elfinder').elfinder({
                    url : '<?php echo Yii::app()->baseUrl ?>/php/connector.php' // connector URL (REQUIRED)
                    ,lang: 'en',
                    width:'100%',
                    commandsOptions: {
                        getfile: {
                            oncomplete: 'destroy' 
                        }
                    },
                    getFileCallback: function(file) {
                        $('#LinkImage').attr('src',file);
                        $('#NewsForm_image').attr('value',file);
                        $( "#dialog-message" ).dialog( "close" );
                    }
                }).elfinder('instance'); 
                
            };
                
        </script>
        <div id="dialog-message" >
            <div id="elfinder"></div>
        </div>
    </body>
</html>
